package com.chixing.day06.JiChengStaticDemo.getOnceErgodic;

/**
 * 饿汉模式
 * 单例模式:singleton:在内存中 对象 只能实例化一次
 */
public class Bank {
    private static Bank ba = new Bank();

    private Bank() {

    }
    /*
    public Bank(){
        System.out.println("Bank 构造函数");
    }*/
   /* public static Bank getObject(){
        return ba;
    }*/
    public static Bank getInstance() {
        return ba;
    }

    public static void main(String[] args) {
        //Bank 只能实例化一次
    /*
      Bank ba1  = Bank.getObject();
      Bank ba2 = Bank.getObject();
      System.out.println("ba1 === ba2: " + (ba1 == ba2));
      */

        Bank ba1 = Bank.getInstance();
        Bank ba2 = Bank.getInstance();
        Bank ba3 = Bank.getInstance();
        System.out.println("ba1 === ba2: " + (ba1 == ba2));
    }
}
